<template>
    <h2 style="text-align: center">用户添加借款</h2>
    <table border="1">
        <tr>
            <td>借款名称</td>
            <td>{{ info.BI_name }}</td>
        </tr>
        <tr>
            <td>借款最高金额</td>
            <td>{{ info.BI_maxmoney }}</td>
        </tr>
        <tr>
            <td>借款年限</td>
            <td>{{ info.BI_year }}</td>
        </tr>
        <tr>
            <td>借款金额</td>
            <td>
                <input type="text" v-model="UB_money">
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="借款" @click="add()">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import {ref,onMounted} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import axios from 'axios'
import { useStore } from '../store/index.ts'

const store = useStore()
const router = useRouter()
const route = useRoute()

const UB_money = ref('')
const info = ref({
    BI_id:"",
    BI_name:"",
    BI_maxmoney:"",
    BI_year:"",
    BT_id:"",
    BI_result:"",
    BI_date:""
})
onMounted(()=>{
    fan()
})
const fan = () => {
    axios({
        url:"http://localhost:52342/api/Borrow/BorrowFan",
        method:"get",
        params:{
            BI_id:route.query.BI_id
        }
    })
    .then((res) => {
        console.log(res.data)
        info.value=res.data
    })
    .catch((err) => {
        console.log(err)
    })
}

const add = () => {
    axios({
        url:"http://localhost:52342/api/Borrow/BorrowUserAdd",
        method:"post",
        data:{
            BI_id:route.query.BI_id,
            UB_money:UB_money.value,
            Uid:store.Uid
        }
    })
    .then((res) => {
        console.log(res.data)
        if(res.data>0){
            alert("借款成功")
            router.push("/BorrowUserShow")
        }else{
            alert("借款失败")
            return
        }
    })
    .catch((err) => {
        console.log(err)
    })
}


</script>


